import os
from datetime import datetime
def ModCreate(mainModuleName, subModuleName):
    moduleName = mainModuleName + subModuleName
    templatePath = os.getcwd() + "\Template"
    newModulePath = os.getcwd() + "\\" + moduleName
    
    if(os.path.exists(newModulePath)):
        pass
    else:
        os.mkdir(newModulePath)
    
    for root, dirs, files in os.walk(templatePath):
        for file in files: 
            if(("" != subModuleName) and ("Rte" in file)):
                pass
            else:
                tempFilePath = root + "\\" + file
                tempFileObject = open(tempFilePath, "r")
                
                newModuleFilePath = newModulePath + "\\" + file.replace("Mod", moduleName)
                newModuleFileObject = open(newModuleFilePath, "w")
                
                lines = tempFileObject.readlines()
                for line in lines:
                    line = line.replace("$Mod$", moduleName)
                    line = line.replace("$MOD$", moduleName.upper())
                    line = line.replace("$MainMod$", mainModuleName)
                    line = line.replace("$Name$", "Yueting.Ben")
                    line = line.replace("$Date$", str(datetime.today().date()))
                    if(subModuleName != ""):
                        line = line.replace("$TypeHeader$", "#include \"" + mainModuleName + ".h\"")
                        line = line.replace("$RteHeader$", "")
                        
                        if("$MainModLine$" in line):
                            pass
                        else:
                            newModuleFileObject.write(line)

                    else:
                        line = line.replace("$TypeHeader$", "#include \"PlatformCfg.h\"")
                        line = line.replace("$RteHeader$", "\n#include \"" + mainModuleName + "Rte.h\"")
                    
                        if("$MainModLine$" in line):
                            line = line.replace("$MainModLine$", "")
                            
                        newModuleFileObject.write(line)

        # print(filePath)
    pass

if __name__ == "__main__":
    ModCreate(mainModuleName = "Ea", subModuleName = "")
    input("Ok")
